import {
  delMenuReq,
  getAllMenusReq,
  getUserMenusReq
} from '@/service/modules/menu'
import { reactive } from 'vue'

export function useMenu() {
  const variables = reactive({
    userMenus: [],
    allMenus: []
  })
  const getUserMenus = async () => {
    const res = await getUserMenusReq()
    if (res.resp_code === 0) {
      variables.userMenus = res.data
    }
  }

  const getAllMenus = async () => {
    const res = await getAllMenusReq()
    if (res.resp_code === 0) {
      variables.allMenus = res.data
    }
  }

  const delMenu = async (id: number) => {
    const res = await delMenuReq(id)
    if (res.resp_code === 0) {
      getAllMenus()
    }
  }
  return { variables, getUserMenus, getAllMenus, delMenu }
}
